<?php
/**
 * Created by PhpStorm OF yuyi.
 * User: YUYI
 * Date: 2018/5/17 0017
 * Time: 上午 9:08
 * Administrator
 */

namespace app\index\controller;


use app\common\controller\Base;
use app\common\model\Users;
use app\common\service\UserService;

class Auth extends Base
{
    protected $isPublic = true;
    public function index()
    {
        return $this->fetch();
    }

    public function login()
    {
        if (!$this->request->isPost()){
            $this->error('非法访问。');
        }
        $user = Users::get(['email'=>input('email'),'password'=>input('password')]);
        if ($user){
            $user->token = md5($user->email.$user->password.time());
            UserService::setUserInfo($user);
            $this->redirect('/index/admin');
        }
        $this->error('登录失败');
    }

    public function loginOut()
    {
        UserService::delUserInfo();
        $this->success('登出成功','/');
    }
}